// useState中的数据如果是一个基础类型则不需要去指定类型，复杂类型指定
// 语法 const [count,setCount] = useState<number>(100)
import { useState, useRef } from 'react'
import Child from './components/Child'

const App = () => {
  const [count, setCount] = useState(100)
  const changeCount = (n: number) => {
    setCount((v) => v + n)
  }

  // 复杂类型，在声明时要指定类型
  const [users, setUsers] = useState<ITest.IUser[]>([])

  // ref
  const childRef = useRef<ITest.IUser>(null!)

  return (
    <div>
      <h3>App组件</h3>
      <hr />
      <Child count={count} changeCount={changeCount} ref={childRef}>
        <div>我是slot</div>
      </Child>
      <button
        onClick={() => {
          console.log(childRef.current.id)
        }}
      >
        获取child函数组件中它的对外暴露出来数据
      </button>
    </div>
  )
}

export default App
